using System;
using System.Collections.Generic;
using UnityEngine;
using QFramework;

namespace ProjectSurvivor
{
	public partial class SimpleBall : ViewController
	{
		private List<Ball> mBalls = new List<Ball>();
		
		private void Start()
		{
			Global.SimpleBallCount.Or(Global.AdditionFlyingCount)
				.Register(createBalls)
				.UnRegisterWhenGameObjectDestroyed(gameObject);
			createBalls();
		}

		private void createBall()
		{
			mBalls.Add(Ball.Instantiate()
				.SyncPosition2DFrom(this)
				.Show());
		}

		private void createBalls()
		{
			int addCount = Global.SimpleBallCount.Value + Global.AdditionFlyingCount.Value - mBalls.Count;

			for (int i = 0; i < addCount; i++)
			{
				createBall();
			}
		}
	}
}
